<!--考场管理-->
<template>
  <div>
    <el-form :inline="true" :model="requestData" style="width: 100%;margin-bottom: -10px;margin-top: -10px;" label-width="65px">
      <el-form-item label="名称">
        <el-input size="mini" v-model="requestData.map.tr_name"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button size="mini" type="success" icon="el-icon-search" @click="searchInfo">查询</el-button>
        <el-button size="mini" icon="el-icon-search" @click="clearSearchInfo">重置</el-button>
        <el-button size="mini" type="danger" icon="el-icon-delete" @click="deleteInfoList">删除</el-button>
        <el-button size="mini" type="primary" icon="el-icon-circle-plus" @click="addInfo">添加</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="tableData"
      style="width: 100%"
      border
      @selection-change="handleSelectionChange">
      <el-table-column
        align="center"
        type="selection"
        width="55">
      </el-table-column>
      <el-table-column
        align="center"
        prop="tr_name"
        label="名称"
        minWidth="120">
      </el-table-column>
      <el-table-column
        align="center"
        prop="userNum"
        label="学生数"
        minWidth="120">
      </el-table-column>
      <el-table-column
        align="center"
        prop="roomPaperNum"
        label="试题数"
        minWidth="120">
      </el-table-column>
      <el-table-column
        align="center"
        prop="tr_password"
        label="考场代码"
        minWidth="120">
      </el-table-column>
      <el-table-column
        align="center"
        prop="tr_time"
        label="创建时间"
        minWidth="120">
      </el-table-column>
      <el-table-column
        label="操作"
        minWidth="180"
        align="center">
        <template slot-scope="scope">
          <el-button size="mini"  type="success" @click="insertTestRoom(scope.$index, scope.row)">进入考场</el-button>
          <el-button size="mini"  @click="editInfo(scope.$index, scope.row)">编辑</el-button>
          <el-button type="danger" icon="el-icon-delete"  size="mini" @click="deleteInfo(scope.$index, scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pageInfo.page"
      :page-sizes="[10, 20, 30, 40,50]"
      :page-size="pageInfo.size"
      layout="total, sizes, prev, pager, next, jumper"
      :total="pageInfo.total">
    </el-pagination>

    <add-info v-if="isShowAddDialog" :isShowAddDialog="isShowAddDialog" @closeDialog="closeDialog"></add-info>
    <update-info v-if="isShowUpdateDialog" :isShowUpdateDialog="isShowUpdateDialog" @closeDialog="closeDialog" :roomInfo="roomInfo"></update-info>
  </div>
</template>
<script>
  import{addTestRoom,deleteTestRoom,updateTestRoom,selectTestRoom,selectUnRoomUser} from "@/api/invigilate";
  import addInfo from "./component/addInfo.vue";
  import updateInfo from "./component/updateInfo.vue"
  export default{
    components: {
      addInfo,
      updateInfo
    },
    created(){
      this.getDataList();
    },
    data(){
      return {
        tableData:[],
        selectList:[],
        isShowAddDialog:false,
        isShowUpdateDialog:false,

        roomInfo:null,

        pageInfo:{
          page:1,//页数
          size:10, //页面大小
          total:0 //页总数
        },
        requestData:{
          pageSize:10,
          pageNum:1,
          map:{
            tr_name:""
          }
        }
      }
    },
    methods:{

      getDataList(){
        selectTestRoom(this.requestData).then(res=>{
            if(res.code == 200){
               this.tableData = res.data.data;
                this.pageInfo.total = res.data.total;
            }
        })
      },

      //进入考场
      insertTestRoom(index,row){
        this.$router.push({ path: '/invigilate/examinationRoom/component/insertRoom/'+row.tr_id });
      },

      editInfo(index,row){
          this.roomInfo = row;
          this.isShowUpdateDialog = true
      },

      deleteInfo(index,row){
        this.selectList = [row];
        this.deleteInfoList();
      },

      //复选框选择的数据
      handleSelectionChange(val){
        this.selectList = val;
      },

      searchInfo(){
        this.getDataList();
      },
      deleteInfoList(){
        if(this.selectList == null || this.selectList.length <= 0){
          this.$message({
            type: 'warning',
            message: '请至少选择一行要删除的数据'
          });
        }else{
          this.$confirm('此操作将删除数据, 是否继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            deleteTestRoom(this.selectList).then(res=>{
              if(res.code == 200){
                this.$message({
                  message: '删除成功',
                  type: 'success'
                });
                this.selectList = [];
                this.getDataList();
              }
            })
          }).catch(() => {

          });
        }
      },

      addInfo(){
        this.isShowAddDialog = true
      },

      clearSearchInfo(){
         this.requestData.map.tr_name = "";
         this.getDataList();
      },

      closeDialog(type){
          if(type == "add"){
              this.isShowAddDialog = false
          }else if(type == "update"){
              this.isShowUpdateDialog = false
          }
          this.getDataList();
      },

      //每页的条数发生改变时调用
      handleSizeChange(size){
        this.requestData.pageSize = size;
        this.pageInfo.size = size;
        this.getDataList();
      },

      //页数发生改变时调用
      handleCurrentChange(page){
        this.requestData.pageNum = page;
        this.pageInfo.page = page;
        this.getDataList();
      },
    }
  }
</script>
